package com.PictureSite.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.PictureSite.Validator.PictureSiteCreatePostValidator;
import com.PictureSite.controller.PictureSiteCreatePostController;
import com.PictureSite.controller.PictureSiteHomeController;
import com.PictureSite.model.PictureSitePostModel;

@SuppressWarnings("serial")
public class PictureSiteCreatePostServlet extends PictureSiteCommonServlet {

	private PictureSiteCreatePostController controller;
	private PictureSitePostModel model = new PictureSitePostModel();
	
	final private static String postView ="post.html";
	
	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
		this.controller = new PictureSiteCreatePostController(getSharedFileService());
	}
	
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		try {
			controller.bindModel(model, postView, resp);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		
		try {
			controller.submitPost(req,resp,model);
			resp.sendRedirect("/");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
